import 'package:flutter_base/common/widgets/CustomAppbar.dart';
import 'package:file_preview/file_preview.dart';
import 'package:flutter/material.dart';

class FilePreViewWidget extends StatefulWidget {
  final String? title;
  final String url;
  const FilePreViewWidget({Key? key, required this.url,  this.title}) : super(key: key);

  @override
  _FilePreViewWidgetState createState() => _FilePreViewWidgetState();
}

class _FilePreViewWidgetState extends State<FilePreViewWidget> {
  @override
  void initState() {
    _initTBS();
    super.initState();
  }
  _initTBS() async {
    var isInit = await FilePreview.tbsHasInit();
    print(isInit);
    if (!isInit) {
      await FilePreview.initTBS();
      return;
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: IconThemeData(color: Colors.black87),
        backgroundColor: Colors.white,
        title: Text(
          widget.title??'附件',
          style: TextStyle(
              fontSize: 18,
              color: Colors.black87,
              fontWeight: FontWeight.normal),
        ),),
      body: FilePreviewWidget(
        width: MediaQuery.of(context).size.width,//宽
        height: MediaQuery.of(context).size.height-44,//高
        path: widget.url,//file path or http url
      ),
    );
  }
}
